<template>
	<view class="wrap">
		<u-gap height="20" bg-color="#f5f5f5"></u-gap>
		<view class="list">
			<view class="list-call">
				<u-radio-group v-model="value" @change="radioGroupChange">
							<u-radio 
								v-for="(item, index) in list" :key="index" 
								:name="item.name"
								:disabled="item.disabled"
							>
								{{item.name}}
							</u-radio>
						</u-radio-group>
			</view>
			
		</view>
		<view class="more-bottom-box">
			<view class="button"  @click="submit()"><text>保存</text></view>
		</view>
		
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
export default {
	data() {
		return {
			
			list: [
							{
								name: 'oracle',
								disabled: false
							},
							{
								name: 'mysql',
								disabled: false
							},
							
						],
						// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
						value: 'oracle',
		};
	},
	onLoad() {
		this.value = uni.getStorageSync('datasource')
		const value = uni.getStorageSync('baseUrl')
		console.log('缓存'+value)
		if(value){
			this.baseUrl=value
		}else{
			this.baseUrl = 'zp450.gnway.cc:8000'
			uni.setStorageSync('baseUrl',this.baseUrl);
			this.$u.toast('请修改并保存');
		}
		
	},
	methods: {
	
				// 选中任一radio时，由radio-group触发
				radioGroupChange(e) {
					console.log(e);
					uni.setStorageSync('datasource', this.value);
					this.value = uni.getStorageSync('datasource')
					this.$u.toast('数据库已经设置为'+this.value);
				},
		submit(){
			
			try {
				
				// https://aidex.vip/api
				// const result = 'http://'+this.baseUrl
				uni.setStorageSync('datasource', this.value);
				this.value = uni.getStorageSync('baseUrl')
				this.$u.toast('数据库已经设置为:'+this.value);
				uni.$emit("baseUrl",this.baseUrl)
				// uni.setStorageSync('baseUrl', result);
				// uni.setStorageSync('baseUrl', 'http://localhost:8092/wms');
			} catch (e) {
				// error
			}
			
			setTimeout(() => {
				uni.navigateTo({
					url: '/pages/sys/login/index'
				});
			}, 500);
		}
		
	}}

</script>
<style lang="scss">
@import 'index.scss';


page {
	background-color: #f5f5f5;
}

/deep/ .u-cell-title {
	padding: 25rpx 30rpx;
	font-size: 30rpx;
}
.ip-text{
	font-size: 10rpx;
}
</style>
